using System;
using System.Collections.Generic;
using System.Linq;
using VMDS.Business.Entities;
using VMDS.Data.SQL;

namespace VMDS.Data
{
    public class SubjectSqlAdapter:ICrudEntity<Subject>
    {
        private ModelContainer _db;

        public ICollection<Subject> GetAll()
        {
            return new List<Subject>(_db.Subjects);
        }

        public Subject GetById(int id)
        {
            return _db.Subjects.SingleOrDefault(x => x.Id == id);
        }

        public void Update(Subject obj)
        {
            Subject old = GetById(obj.Id);
            old.Name = obj.Name;
            
        }

        public void Delete(Subject obj)
        {
            var old = GetById(obj.Id);
            _db.Subjects.DeleteObject(old);
        }

        public void Create(Subject obj)
        {
            Subject old = _db.Subjects.CreateObject();
            old.Name = obj.Name;
            
        }
        public SubjectSqlAdapter(ModelContainer db)
        {
            _db = db;
        }
    }
}